package asia.lxq.cic.service;

import asia.lxq.cic.dao.NoticeMapper;
import asia.lxq.cic.entity.Notice;
import asia.lxq.cic.entity.Result;
import asia.lxq.cic.entity.StatusCode;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NoticeService {

    @Autowired
    NoticeMapper noticeMapper;

    public Result<Object> getLastNoticeList(String column,int value,int page,int pageSize){
        QueryWrapper<Notice> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(column,value);
//        if(column.equals("notice_belong_id")){
//            queryWrapper.eq("notice_notice_id",-1);
//        }
//        if(column.equals("notice_group_id")){
//            queryWrapper.eq("notice_belong_id",-1);
//        }
        queryWrapper.orderByDesc("notice_Date");
        Page<Notice> noticePage = noticeMapper.selectPage(new Page<>(page, pageSize), queryWrapper);
        List<Notice> noticeList = noticePage.getRecords();
        Map<String,Object> resultData=new HashMap<>();
        resultData.put("data",noticeList);
        resultData.put("total",noticePage.getTotal());
        resultData.put("current",noticePage.getCurrent());
        resultData.put("pages",noticePage.getPages());
        return Result.success(resultData);
    }

    public Result<Object> postNotice(Notice notice){
        noticeMapper.insert(notice);
        return Result.success();
    }
}
